package com.ymatou.iapi.userservice.testcase;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.login.parameter.AliUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.SinaWeiBoUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.UnBindThirdPartyAccountDtoBean;
import com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean;
import com.ymatou.iapi.login.service.AliUserRequestDtoCall;
import com.ymatou.iapi.login.service.SinaWeiBoUserRequestDtoCall;
import com.ymatou.iapi.login.service.UnBindThirdPartyAccountDtoCall;
import com.ymatou.iapi.login.service.WeiXinUserRequestDtoCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.UserSafeLevelInfoDtoBean;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.userservice.service.UserSafeLevelInfoDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;
import com.ymttest.utils.constant.ThirdPartyType;

/**
*获取用户安全等级接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UserSafeLevelInfoDto{
	private static UserSafeLevelInfoDtoBean usersafelevelinfodtoBean;
	private static UserSafeLevelInfoDtoCall usersafelevelinfodtoCall;
	
	@BeforeClass
	public static void setUp() throws Exception {
		Logger.createResultFile("获取用户安全等级接口");
	}

	@Before
	public void caseUp() {
		usersafelevelinfodtoBean=new UserSafeLevelInfoDtoBean();
		usersafelevelinfodtoCall=new UserSafeLevelInfoDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(usersafelevelinfodtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserSafeLevelInfoDto_001() {
		Logger.start(true,"通过微信授权登陆，安全等级验证");
		try {
			Logger.comment("新创建微信账号");
			Map user = regByWeiXin(TestDataManager.getPhoneNum());
			int userId = ((Double)user.get("userId")).intValue();
			String loginPas = "654321aB";
			usersafelevelinfodtoBean.setUserId(userId);
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级为低级");
			
			Logger.comment("设置登陆密码");
			setLoginPas("modifyLoginPassword", userId, loginPas);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("设置交易密码");
			setLoginPas("ModifyTradingPassword", userId, JUserCallService.defaultLoginPwd);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("绑定邮箱");
			JUserCallService.BindEmail(userId,TestDataManager.getEmail());
			Thread.sleep(1000);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall.callService();	
			//{"SuccessMessage":"ok","ResponseCode":200,"Success":true,"Result":0}
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("1", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserSafeLevelInfoDto_002() {
		Logger.start(true,"通过微博授权登陆，安全等级验证");
		try {
			Logger.comment("新创建微博账号");
			Map user = regByWeibo(TestDataManager.getPhoneNum());
			int userId = ((Double)user.get("userId")).intValue();
			usersafelevelinfodtoBean.setUserId(userId);
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级为低级");
			
			Logger.comment("设置交易密码");
			setLoginPas("ModifyTradingPassword", userId, JUserCallService.defaultLoginPwd);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserSafeLevelInfoDto_003() {
		Logger.start(true,"通过阿里授权登陆，安全等级为低级");
		try {
			Logger.comment("查找一个未绑定过手机号的微博账号");
			Map user = regByWeibo(TestDataManager.getPhoneNum());
			int userId = ((Double)user.get("userId")).intValue();
			
			new JUserWapper().removeMoblie(userId);
			
			String loginPas = "987654";
			usersafelevelinfodtoBean.setUserId(userId);
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级为低级");
			
			Logger.comment("设置登陆密码");
			setLoginPas("modifyLoginPassword", userId, loginPas);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("绑定邮箱");
			JUserCallService.BindEmail(userId,TestDataManager.getEmail());
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserSafeLevelInfoDto_004() {
		Logger.start(true,"手机号注册用户，设置过登陆密码，安全等级验证");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			regbean.setLoginMail(null);
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId=urrc.getUserid();
			usersafelevelinfodtoBean.setUserId(userId);
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("绑定邮箱");
			JUserCallService.BindEmail(userId,TestDataManager.getEmail());
			Thread.sleep(1000);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("1", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("设置交易密码");
			setLoginPas("ModifyTradingPassword",userId, "456789");
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("1", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
//	@Test
//	@Category(P1.class)
//	@TestCase
//	@Ignore
	//新用户不存在邮箱注册用户了
//	public void Tc_UserSafeLevelInfoDto_005() {
//		Logger.start(true,"邮箱注册用户，设置过登陆密码，安全等级验证");
//		try {
//			Map user = UserCallService.registerUser(TestDataManager.getEmail(), null,null);
//			usersafelevelinfodtoBean.setUserId((Integer)user.get("userId"));
//			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
//			usersafelevelinfodtoCall.callService();			
//			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
//			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
//			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
//			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
	
	@Test
	@Category(P1.class)
	@TestCase//只有手机号或只有邮箱，应该是不能解绑的
	public void Tc_UserSafeLevelInfoDto_006() {
		Logger.start(true,"通过绑定了手机的阿里授权登陆，安全等级验证");
		try {
			Logger.comment("新创建阿里账号");
			Map user = regByAli(TestDataManager.getPhoneNum());
			int userId = ((Double)user.get("userId")).intValue();
			String thirdPartyId=user.get("thirdPartyId").toString();
			Thread.sleep(1000);
			Logger.comment("验证安全等级");
			usersafelevelinfodtoBean.setUserId(userId);
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级为低级");
			Thread.sleep(2000);
			Logger.comment("解绑第三方账号");
			//			Map result = UserCallService.unbindThirdParty(userId, user.get("thirdPartyId").toString(), ThirdPartyType.ALI);
			UnBindThirdPartyAccountDtoBean unBindThirdPartyAccountDtoBean=new UnBindThirdPartyAccountDtoBean();
			unBindThirdPartyAccountDtoBean.setThirdPartyId(thirdPartyId);
			unBindThirdPartyAccountDtoBean.setUserId(userId);
			unBindThirdPartyAccountDtoBean.setThirdPartyType(ThirdPartyType.ALI);
			UnBindThirdPartyAccountDtoCall unbindthird = JUserCallService.unBindThirdPartyAccountDto(unBindThirdPartyAccountDtoBean);
			//{"Success":false,"SuccessMessage":null,"ResponseCode":300,"Result":null,"ErrorCode":null,"LastErrorMessage":"请设置登录账号及密码"}
			
			Logger.verifyEquals("300",unbindthird.getString("ResponseCode") , "验证Code");
			Logger.verifyEquals("false", unbindthird.getString("Success"), "验证是否成功");
			Logger.verifyEquals("请设置登录账号及密码", unbindthird.getString("LastErrorMessage"), "验证Msg信息");
			
			Logger.comment("验证安全等级");
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserSafeLevelInfoDto_007() {
		Logger.start(true,"设置安全问题开启双重验证，安全等级为高级JIRACONN-2522");
		try {
			Logger.comment("新创建微信账号");
			Map user = regByWeiXin(TestDataManager.getPhoneNum());
			int userId = ((Double)user.get("userId")).intValue();
			String loginPas = "654321aB";
			usersafelevelinfodtoBean.setUserId(userId);
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级为低级");
			
			Logger.comment("设置登陆密码");
			setLoginPas("modifyLoginPassword", userId, loginPas);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall=new UserSafeLevelInfoDtoCall();
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();	
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("设置交易密码");
			setLoginPas("ModifyTradingPassword", userId, JUserCallService.defaultLoginPwd);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall=new UserSafeLevelInfoDtoCall();
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("绑定邮箱");
			JUserCallService.BindEmail(userId,TestDataManager.getEmail());
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall=new UserSafeLevelInfoDtoCall();
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("1", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			AuthCallServiceV2.setSecurityQuestion(userId);
			AuthCallServiceV2.setSecurity(userId, true);
			Logger.comment("验证用户安全等级");
			boolean waitResult=true;
			int redo=0;
			while(waitResult){
				usersafelevelinfodtoCall=new UserSafeLevelInfoDtoCall();
				usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
				usersafelevelinfodtoCall.callService();
				waitResult=!usersafelevelinfodtoCall.getString("Result").equals("2");
				redo++;
				Logger.debug("查询次数:"+redo);
				if(redo>10){
					waitResult=false;
				}
			}
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("2", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserSafeLevelInfoDto_008() {
		Logger.start(true,"设置安全问题关闭双重验证，安全等级为高级JIRACONN-2522");
		try {
			Logger.comment("新创建微信账号");
			Map user = regByWeiXin(TestDataManager.getPhoneNum());
			int userId = ((Double)user.get("userId")).intValue();
			String loginPas = "654321aB";
			usersafelevelinfodtoBean.setUserId(userId);
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级为低级");
			
			Logger.comment("设置登陆密码");
			setLoginPas("modifyLoginPassword", userId, loginPas);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall=new UserSafeLevelInfoDtoCall();
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();	
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall=new UserSafeLevelInfoDtoCall();
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("设置交易密码");
			setLoginPas("ModifyTradingPassword", userId, JUserCallService.defaultLoginPwd);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall=new UserSafeLevelInfoDtoCall();
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("0", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			
			Logger.comment("绑定邮箱");
			JUserCallService.BindEmail(userId,TestDataManager.getEmail());
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall=new UserSafeLevelInfoDtoCall();
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("1", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
			AuthCallServiceV2.setSecurityQuestion(userId);
			AuthCallServiceV2.setSecurity(userId, false);
			Logger.comment("验证用户安全等级");
			usersafelevelinfodtoCall=new UserSafeLevelInfoDtoCall();
			usersafelevelinfodtoCall.setData(usersafelevelinfodtoBean);
			usersafelevelinfodtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, usersafelevelinfodtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("ok", usersafelevelinfodtoCall.getString("SuccessMessage"), "验证Msg信息");
			Logger.verifyEquals("true", usersafelevelinfodtoCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals("1", usersafelevelinfodtoCall.getString("Result"), "验证安全等级");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 创建微信账号
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	private Map regByWeiXin(String phone) throws ClientProtocolException, IOException{
		WeiXinUserRequestDtoBean regBean = new WeiXinUserRequestDtoBean();
		WeiXinUserRequestDtoCall regCall = new WeiXinUserRequestDtoCall();
		String loginId = "LoginWeiXiUser_"+TestDataManager.getRandomNum(5);
		String openId = "RegopenId_"+TestDataManager.getRandomNum(7);
		regBean.setCountry("China");
		regBean.setProvince("Shanghai");
		regBean.setCity("Shanghai");
		regBean.setClientIp("1.1.1.1");
		regBean.setHeadimgurl("");
		regBean.setName(loginId);
		regBean.setOId(openId);
		regBean.setRegSource(AppSourceEnum.MainSite);
		regBean.setMobile(TestDataManager.getPhoneNum());
		regBean.setSex("Femail");
		regBean.setTimeOut(new Date().getTime());
		regBean.setTSource(TerminalSourceEnum.PC);
		regBean.setUnionId("unionId_"+TestDataManager.getRandomNum(4));
		regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(10));
		regBean.setMobile(phone);
		regCall.setData(regBean);
		regCall.callService();	
		if(regCall.getString("Success").equals("false")){
			regCall=new WeiXinUserRequestDtoCall();
			regBean.setUnionId("unionId_"+TestDataManager.getRandomNum(4));
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(10));
			regCall.setData(regBean);
			regCall.callService();	
		}
		Map<String, Object> user = new HashMap<String, Object>();
		user.put("userId", regCall.getResult().get("UserId"));
		user.put("loginId", loginId);
		return user;
	}
	
	/**
	 * 创建微博账号
	 * @return
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	private Map regByWeibo(String phone) throws ClientProtocolException, IOException{
		SinaWeiBoUserRequestDtoBean regBean = new SinaWeiBoUserRequestDtoBean();
		SinaWeiBoUserRequestDtoCall regCall = new SinaWeiBoUserRequestDtoCall();
		String loginId = "BindWeibo_"+TestDataManager.getRandomNum(10);
		regBean.setSWeiboUserId(loginId);
		regBean.setSName(loginId);
		regBean.setSMail(TestDataManager.getEmail());
		regBean.setSMobile(TestDataManager.getPhoneNum());
		regBean.setClientIp("120.1.1.1");
		regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
		regBean.setTerminalSource(TerminalSourceEnum.IOS);
		regBean.setRegSource(AppSourceEnum.App);
		regBean.setMobile(TestDataManager.getPhoneNum());
		regCall.setData(regBean);
		regCall.callService();	
		Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
		
		Map<String, Object> user = new HashMap<String, Object>();
		user.put("userId", regCall.getResult().get("UserId"));
		user.put("loginId", loginId);
		return user;
	} 
	
	/**
	 * 创建阿里账号
	 * @return
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	private Map regByAli(String phone) throws ClientProtocolException, IOException{
		AliUserRequestDtoBean aliuserregbean = new AliUserRequestDtoBean();
		AliUserRequestDtoCall aliuserregCall = new AliUserRequestDtoCall();
		String aliUserId = "ali_"+TestDataManager.getRandomNum(7);
		aliuserregbean.setSAliUserId(aliUserId);
		aliuserregbean.setSRealName(aliUserId);
		aliuserregbean.setSEmail("12456@123.com");
		aliuserregbean.setTerminalSource(TerminalSourceEnum.IOS);
		aliuserregbean.setRegSource(AppSourceEnum.App);
		aliuserregbean.setMobile(TestDataManager.getPhoneNum());
		aliuserregbean.setClientIp("120.1.1.1");
		aliuserregbean.setTokenTimeOut((new Date()).getTime());
		if(phone!=null){
			aliuserregbean.setMobile(phone);
		}
		aliuserregCall.setData(aliuserregbean);
		aliuserregCall.callService();			
		Logger.verifyEquals("注册成功", aliuserregCall.getString("SuccessMessage"), "验证返回的Message信息");
				
		Map<String, Object> user = new HashMap<String, Object>();
		user.put("userId", aliuserregCall.getResult().get("UserId"));
		user.put("loginId", aliUserId);
		user.put("thirdPartyId", aliUserId);
		return user;
	} 
	
	/**
	 * 设置登陆密码(pasType: modifyLoginPassword)
	 * @param userId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	private void setLoginPas(String pasType, int userId, String pwd) throws Exception{
		if(pasType.toLowerCase().equals("ModifyTradingPassword".toLowerCase())){
			JUserCallService.UpdateTradingPwd(userId, pwd);
		}
		else if (pasType.toLowerCase().equals("modifyLoginPassword".toLowerCase())){
			JUserCallService.UpdateLoginPwd(userId, pwd);
		}else{
			throw new Exception("设置密码失败,pasType未识别:"+pasType);
		}
		
	}
}